//https://leetcode.cn/problems/implement-queue-using-stacks/
package codeRandomThoughts.Test232用栈实现队列;

import java.util.Stack;

public class MyQueue {
    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        //只有输出栈为空的时候才补充数据
        if (stackOut.isEmpty()) {
            while (!stackIn.isEmpty()) {
                Integer pop = stackIn.pop();
                stackOut.push(pop);
            }
        }
        return stackOut.pop();
    }

    public int peek() {
        int pop = this.pop();
        stackOut.push(pop);
        return pop;
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
